<?

	if( $_REQUEST[ "JC_translation_query" ] == "insert" ) {

		echo $query = "

			INSERT INTO `translation` (
				`FKT`			,
				`FKF`			,
				`FK`			,
				`language`		,
				`original`		,
				`translation`	,
				`accuracy`		,
				`type`			,
				`log`			,
				`insert`
			) VALUES (
				'" . $_REQUEST[ "JC_translation_FKT"				] . "',
				'" . $_REQUEST[ "JC_translation_FKF"				] . "',
				'" . $_REQUEST[ "JC_translation_FK"				] . "',
				'" . $_REQUEST[ "JC_translation_language"		] . "',
				'" . $_REQUEST[ "JC_translation_original"		] . "',
				'" . $_REQUEST[ "JC_translation_translation"	] . "',
				'" . $_REQUEST[ "JC_translation_accuracy"		] . "',
				'" . $_REQUEST[ "JC_translation_type"			] . "',
				'',
				NOW( )
			)

		";

	JC_query( $query );

?>

	<script>

		parent.document.getElementById( 'JC_translation_FK'		).value = parseInt( parent.document.getElementById( 'JC_translation_FK' ).value ) + 1;
		parent.document.getElementById( "JC_translation_query"	).value = "";
		parent.document.getElementById( "JC_translation"			).setAttribute( 'target', '' );
		parent.document.getElementById( "JC_translation"			).submit( );

	</script>

<?

		exit( );

	}

?>



<b>Translation</b><br /><hr />

<form id="JC_translation" method="post">

	<table>
		<tr>
			<th>Table</th>
			<th>Field</th>
		</tr>
		<tr>
			<td>

				<select id="JC_translation_FKT" name="JC_translation_FKT">

					<option></option>

					<? foreach( $_SESSION[ "JC_scheme" ] as $key => $value) { ?>

						<option <?= $_REQUEST[ "JC_translation_FKT" ] == $key ? "selected" : "" ?>><?= $key ?></option>

					<? } ?>

				</select>

				<? // function JC_ST( $id, $name, $valid = array( ), $invalid = array( "comment" ), $selected = array( ), $multiple = false ) { // Select Table } ?>

			</td>
			<td><a href="#this" class="form" onclick="document.getElementById( 'JC_translation' ).submit( );">Field</a></td>
		</tr>
	</table><hr />



	<? if( $_REQUEST[ "JC_translation_FKT" ] ) { ?>

		<table>
			<tr>
				<th>Field</th>
				<th>Key</th>
				<th>Language</th>
				<th>Ratio</th>
				<th>Select</th>
			</tr>
			<tr>
				<td>

					<select name="JC_translation_FKF">

						<option></option>

						<? foreach( $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_translation_FKT" ] ] as $key => $value) { ?>

							<? if( strpos( $key, "_I18N" ) === false ) continue; ?>

							<option <?= $_REQUEST[ "JC_translation_FKF" ] == $key ? "selected" : "" ?>><?= $key ?></option>

						<? } ?>

					</select>

					<? // function JC_SF( $table, $id, $name, $valid = array( ), $invalid = array( "comment" ), $selected = array( ), $multiple = false ) { // Select Field } ?>

				</td>
				<td><input type="text" id="JC_translation_FK" name="JC_translation_FK" value="<?= $_REQUEST[ "JC_translation_FK" ] ?>" size="6" class="right" /></td>
				<td>
					<select name="JC_translation_language">
						<option></option>
						<option <?= $_REQUEST[ "JC_translation_language" ] == "VI" ? "selected" : "" ?>>VI</option>
						<option <?= $_REQUEST[ "JC_translation_language" ] == "EN" ? "selected" : "" ?>>EN</option>
						<option <?= $_REQUEST[ "JC_translation_language" ] == "KO" ? "selected" : "" ?>>KO</option>
					</select>
				</td>
				<td>
					<select name="JC_translation_ratio">
						<option <?= $_REQUEST[ "JC_translation_ratio" ] == "100:0" ? "selected" : "" ?>>100:0</option>
						<option <?= $_REQUEST[ "JC_translation_ratio" ] == "75:25" ? "selected" : "" ?>>75:25</option>
						<option <?= $_REQUEST[ "JC_translation_ratio" ] == "50:50" ? "selected" : "" ?>>50:50</option>
						<option <?= $_REQUEST[ "JC_translation_ratio" ] == "25:75" ? "selected" : "" ?>>25:75</option>
						<option <?= $_REQUEST[ "JC_translation_ratio" ] == "0:100" ? "selected" : "" ?>>0:100</option>
					</select>
				</td>
				<td><a href="#this" class="form" onclick="document.getElementById( 'JC_translation' ).submit( );">Select</a></td>
			</tr>
		</table><hr />



		<? if( $_REQUEST[ "JC_translation_FKF" ] && $_REQUEST[ "JC_translation_FK" ] && $_REQUEST[ "JC_translation_language" ] ) { ?>

			<?

				$query = "SELECT `" . str_replace( "_I18N", "", $_REQUEST[ "JC_translation_FKF" ] ) . "` FROM `" . $_REQUEST[ "JC_translation_FKT" ] . "` WHERE `key` = '" . $_REQUEST[ "JC_translation_FK" ] . "'";

				$RS = JC_query( $query );

				if( $RS ) $record = $RS -> fetch_array( );

			?>

			<table>
				<tr>
					<th>Original</th>
					<th>I18N</th>
					<th colspan="5" title="The unit of this unit is '%'." class="help">Accuracy</th>
					<th colspan="3">Type</th>
					<th>Insert</th>
					<th>Pass</th>
				</tr>
				<tr>
					<td><input type="text" name="JC_translation_original" value="<?= $record[ 0 ] ?>" title="<?= $record[ 0 ] ?>" size="36" readonly /></td>
					<td><input type="text" name="JC_translation_translation" id="JC_translation_translation" size="36" /></td>

					<td><input type="radio"	name="JC_translation_accuracy" value="100"		/> 100<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_accuracy" value="75"		/> 75<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_accuracy" value="50"		/> 50<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_accuracy" value="25"		/> 25<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_accuracy" value="0" checked	/> 0<br		class="form" /></td>

					<td><input type="radio"	name="JC_translation_type" value="Equivalent"			/> Equivalent<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_type" value="Translation" checked	/> Translation<br	class="form" /></td>
					<td><input type="radio"	name="JC_translation_type" value="Pronouciation"			/> Pronouciation<br	class="form" /></td>

					<td>

						<input type="hidden" id="JC_translation_query"	name="JC_translation_query" value="" />

						<a
							href	= "#this"
							class	= "form"
							onclick	= "
								document.getElementById( 'JC_translation_query' ).value = 'insert';
								document.getElementById( 'JC_translation' ).setAttribute( 'target', 'JC_asynchronous' );
								document.getElementById( 'JC_translation' ).submit( );
							"
						>Insert</a>

					</td>
					<td>
						<a
							href	= "#this"
							class	= "form"
							onclick	= "
								document.getElementById( 'JC_translation_FK' ).value = parseInt( document.getElementById( 'JC_translation_FK' ).value ) + 1;
								document.getElementById( 'JC_translation' ).submit( );
							"
						>Pass</a>
					</td>
				</tr>
			</table><hr />



			<? $ratio = explode( ":", $_REQUEST[ "JC_translation_ratio" ] ); ?>

			<table class="full">
				<tr>

					<? if( $ratio[ 0 ] ) { ?>

						<th style="width: <?= $ratio[ 0 ] ?>%">Translate</th>

					<? } ?>

					<? if( $ratio[ 1 ] ) { ?>

						<th style="width: <?= $ratio[ 1 ] ?>%">Dictionary</th>

					<? } ?>

				</tr>
				<tr>


					<? if( $ratio[ 0 ] ) { ?>

						<td><iframe src="http://translate.google.com/#auto|<?= strtolower( $_REQUEST[ "JC_translation_language" ] ) ?>|<?= urlencode( $record[ 0 ] ) ?>" style="height: 300px" class="full"></iframe></td>

					<? } ?>

					<? if( $ratio[ 1 ] ) { ?>

						<td><iframe src="http://www.google.com/dictionary?langpair=<?= $_REQUEST[ "JC_translation_language" ] == "KO" ? "en" : "ko" ?>|<?= $_REQUEST[ "JC_translation_language" ] == "KO" ? "ko" : "en" ?>&q=<?= urlencode( $record[ 0 ] ) ?>&hl=<?= $_REQUEST[ "JC_translation_language" ] == "KO" ? "ko" : "en" ?>&aq=f" style="height: 300px;" class="full"></iframe></td>

					<? } ?>

				</tr>
			</table>

			<script>

				function

				setTimeout( "document.getElementById( 'JC_translation_translation' ).focus( )", 3000 );

			</script>

		<? } ?>

	<? } ?>

</form>
